/*
 * $RCSfile: Processor_54_TimeoutBack.java,v $
 * $Revision: 1.1  $
 * $Date: 2012-8-17  $
 *
 * Copyright (C) 2005 Bettem, Inc. All rights reserved.
 *
 * This software is the proprietary information of Bettem, Inc.
 * Use is subject to license terms.
 */
package com.dzpk.gameserver.module.main.processor;

import java.util.Map;

import org.apache.log4j.Logger;

import com.i366.Constant;
import com.i366.cache.Cache;
import com.i366.room.model.RoomPersion;
import com.i366.room.model.impl.Room;
import com.i366.service.RoomService;
import com.work.client.util.I366ClientPickUtil;
import com.work.comm.util.I366PickUtil;
import com.work.db.model.UserInfo;
import com.work.engine.protocal.request.Request;
import com.work.engine.server.handler.Handler;

/**
 * ˵��:��ҳ�ʱ���¼���
 * <p>Title: Processor_54_TimeoutBack</p> 
 * <p>Description: </p> 
 * <p>Copyright: Copyright (c) 2006</p> 
 * @author shenxing.ruan
 * @version 1.0
 */
public class Processor_54_TimeoutBack extends Handler{

	private Logger logger = Logger.getLogger(Processor_54_TimeoutBack.class);
	public byte[] handleRequest() {
		logger.debug("Processor_54_TimeoutBack userId is : " + this.getGameRequest().getUserId());
		//=======================�����֤=================
		Request request = getGameRequest();
		RoomService.updateUser(request);
		int[][] int2 = {{130,I366ClientPickUtil.TYPE_INT_4},
				{60,I366ClientPickUtil.TYPE_INT_1},
				{61,I366ClientPickUtil.TYPE_INT_1},
		};
		Map<Integer, Object> map = I366ClientPickUtil.pickAll(request.getBt(), int2);
		int seatId = (Integer)map.get(61);
		try {
			UserInfo userInfo = Cache.getOnlineUserInfo().get(request.getUserId());
			if (userInfo == null) {
				return pusUser(1);
			}
			Room room = Cache.getRoom(userInfo.getRoomId(), userInfo.getRoomPath());
			RoomPersion roomPersion = room.getAudMap().get(request.getUserId());
			if (roomPersion == null) {
				return null;
			}
			Object[][] objs2 = {
					{60,0,I366ClientPickUtil.TYPE_INT_1},
					{130,request.getUserId(),I366ClientPickUtil.TYPE_INT_4},
					{61,seatId,I366ClientPickUtil.TYPE_INT_1}
			};
			byte[] bytes = I366PickUtil.packAll(objs2, Constant.REQ_GAME_TIMEOUT_BACK);
			room.getRoomService().send(bytes);
			return null;
		} catch (Exception e) {
			return pusUser(1);
		}
	}

	public byte[] pusUser(int status ) {
		Object[][] objs2 = {
				{60,status,I366ClientPickUtil.TYPE_INT_1}
		};
		byte[] bytes = I366PickUtil.packAll(objs2, Constant.REQ_GAME_TIMEOUT_BACK);
		return bytes;
	}
	
	public Object makeObject() throws Exception {
		return new Processor_54_TimeoutBack();
	}
	
	
}

